package com.example.cinema.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import java.util.List;
//通过适配器
public class CommentAdapter<T> extends BaseAdapter {

    private LayoutInflater inflater;
    private List<T>  data;
    private int layoutid;
    private int Brid;

    public CommentAdapter(Context context, List<T> data, int layoutid, int brid) {
        this.inflater = LayoutInflater.from(context);
        this.data = data;
        this.layoutid = layoutid;
        Brid = brid;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    FuYong fuYong;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null)
        {
            fuYong = new FuYong();
            fuYong.dataBinding = DataBindingUtil.inflate(inflater,layoutid,parent,false);
            convertView = fuYong.dataBinding.getRoot();
            convertView.setTag(fuYong);
        }else {
            fuYong = (FuYong) convertView.getTag();
        }
        fuYong.dataBinding.setVariable(Brid,data.get(position));
        return convertView;
    }

    class FuYong
    {
        private ViewDataBinding dataBinding;
    }



}
